package com.asktgapp.user.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.asktgapp.R;
import com.asktgapp.base.BaseFragment;
import com.asktgapp.modulebase.common.util.Util;
import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.beta.UpgradeInfo;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * time:2018/1/8
 * Create By ZhaoKai
 * Email: dczk@foxmail.com
 * Description:
 */

public class UpdateFragment extends BaseFragment {

    @InjectView(R.id.tv_check_update)
    TextView checkUpdate;
    @InjectView(R.id.tvCode)
    TextView tvCode;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_check_update, container, false);
        ButterKnife.inject(this, viewGroup);
        return super.onCreateView(inflater, viewGroup, savedInstanceState);
    }

    @Override
    protected void initView(View rootView) {
        getBaseActivity().setBackNavigationIcon();

        tvCode.setText("当前版本：" + Util.getAppVersion(getActivity()));
        checkUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                VersonControl.beginVersionUpdate(getActivity(), 19, "com.asktgapp", new VersonControl.onDontNeedUpdateListener() {
//                    @Override
//                    public void onDontNeedUpdate() {
//
//                        showTost("已经是最新版",1);
//                    }
//                });
                /***** 获取升级信息 *****/
                UpgradeInfo upgradeInfo = Beta.getUpgradeInfo();

                if (upgradeInfo == null) {
                    showTost("无升级信息",0);
                    return;
                }
                Beta.checkUpgrade();
            }
        });

    }

    @Override
    public void loadData() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
